package com.it.base.resposne;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * @program: auth
 * @description: 自定义返回值
 * @author: Lefnmg
 * @create: 2018-11-24 22:37
 **/
public class JsonData extends HashMap<String, Object> {
    private static final long serialVersionUID = 1L;

    public JsonData() {
        this.put("code", 200);
        this.put("msg", "success");
        this.put("date",new Date());
    }

    public static JsonData error() {
        return error(500, "未知异常，请联系管理员");
    }

    public static JsonData error(String msg) {
        return error(500, msg);
    }

    public static JsonData error(int code, String msg) {
        JsonData data = new JsonData();
        data.put("code", code);
        data.put("msg", msg);
        data.put("date",new Date());
        return data;
    }

    public static JsonData ok(String msg) {
        JsonData data = new JsonData();
        data.put("msg", msg);
        return data;
    }

    public static JsonData ok(Map<String, Object> map) {
        JsonData data = new JsonData();
        data.putAll(map);
        return data;
    }

    public static JsonData ok() {
        return new JsonData();
    }
    @Override
    public JsonData put(String key, Object value) {
        super.put(key, value);
        return this;
    }
}
